package com.ssdp.utils;

import com.ssdp.dto.UserDTO;

/**
 * @author syo 2319615164@qq.com
 * @description ThreadLocal存储用户脱敏信息
 * @date 2024/3/14
 * @Copyright syo
 */
public class UserHolder {
    /**
     * ThreadLocal对象
     */
    private static final ThreadLocal<UserDTO> tl = new ThreadLocal<>();

    /**
     * 保存用于脱敏信息
     */
    public static void saveUser(UserDTO userDto){
        tl.set(userDto);
    }

    /**
     * 获取用户脱敏信息
     * @return 有则返回，无则返回null
     */
    public static UserDTO getUser(){
        return tl.get();
    }

    /**
     * 移除ThreadLocal所对应存储的数据
     */
    public static void removeUser(){
        tl.remove();
    }
}
